package com.vilen.muti.v_learn_yuanquan.app;

import android.app.Activity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;


public class MainActivity extends Activity {
    ProgressBar mProgressBar;
    Button button_player;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mProgressBar = (ProgressBar) findViewById(R.id.progressBar1);
        button_player = (Button) findViewById(R.id.button_player);
        button_player.setOnClickListener(listener);
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(view.getId() == R.id.button_player) {
                Thread thread = new Thread(new Runnable(){

                    @Override
                    public void run() {
                        int progressBarMax =mProgressBar.getMax();
                        try {
                            while(progressBarMax!=mProgressBar.getProgress())
                            {
                                //No.1
                                //开始写代码，请实现用线程和ProgressBar每1秒显示10%的进度，10秒完成100%的进度，并显示在ProgressBar上。
                                int stepProgress = 0;
                                for(int i=0;i<10;i++) {
                                    Thread.sleep(1000);
                                    stepProgress+=10;
                                    mProgressBar.setProgress(stepProgress);
                                }



                                //end_code
                            }

                        } catch(InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                });

                thread.start();
            }


        }
    };
}

